package com.pcbly.web.action.system;

import java.util.Date;
import java.util.List;

import com.pcbly.web.action.BaseAction;
import com.pcbly.web.bean.table.ColumnPropertyBean;
import com.pcbly.web.business.table.ColumnPropertyService; 

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

public class ColumnPropertyAction extends BaseAction<ColumnPropertyBean> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5101406577145455156L;

	protected ColumnPropertyService columnPropertyService; 
	
	public void setColumnPropertyService(ColumnPropertyService columnPropertyService) {
		this.columnPropertyService = columnPropertyService;
	}
	private ColumnPropertyBean columnProperty;
	
	private List<ColumnPropertyBean> columnPropertyBeans;
	
	private String columnId;
	
	private String iflag;
	
	
	public List<ColumnPropertyBean> getColumnPropertyBeans() {
		return columnPropertyBeans;
	}

	public void setColumnPropertyBeans(List<ColumnPropertyBean> columnPropertyBeans) {
		this.columnPropertyBeans = columnPropertyBeans;
	}

	public String getColumnId() {
		return columnId;
	}

	public void setColumnId(String columnId) {
		this.columnId = columnId;
	}

	public String getIflag() {
		return iflag;
	}

	public void setIflag(String iflag) {
		this.iflag = iflag;
	}
	private String orderBy; 
	
	private boolean asc = true;
	
	public boolean isAsc() {
		return asc;
	}

	public void setAsc(boolean asc) {
		this.asc = asc;
	}
	
	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}
	
	public ColumnPropertyBean getColumnProperty() {
		return columnProperty;
	} 
	public void setColumnProperty(ColumnPropertyBean columnProperty) {
		this.columnProperty = columnProperty;
	}
	public String view() throws Exception {
		long startTime = System.currentTimeMillis();
		columnProperty=columnPropertyService.getColumnPropertyBeanById(getId());
		startTime = System.currentTimeMillis() - startTime;
		if (log.isDebugEnabled()) {
			log.debug("time ms:::::" + startTime);
			System.out.println("time ms:::::" + startTime);
		}
		return super.view();
	}
	public String update() throws Exception {
		long startTime = System.currentTimeMillis();
		setMyMessage(null);
		columnProperty=columnPropertyService.getColumnPropertyBeanById(getId());
		startTime = System.currentTimeMillis() - startTime;
		if (log.isDebugEnabled()) {
			log.debug("time ms:::::" + startTime);
			System.out.println("time ms:::::" + startTime);
		}
		return super.update();
	}
	public String index() throws Exception {
		long startTime = System.currentTimeMillis();
 
		startTime = System.currentTimeMillis() - startTime;
		if (log.isDebugEnabled()) { 
			log.debug("time ms:::::" + startTime); 
			System.out.println("time ms:::::" + startTime);
		}
		return super.index();
	}
	public String add() throws Exception { 
		long startTime = System.currentTimeMillis();
		setMyMessage(null);
		columnProperty=new ColumnPropertyBean();
		startTime = System.currentTimeMillis() - startTime;
		if (log.isDebugEnabled()) {
			log.debug("time ms:::::" + startTime);
			System.out.println("time ms:::::" + startTime);
		}
		return super.add();
	}
	public String save() throws Exception {
		long startTime = System.currentTimeMillis();
		if (log.isDebugEnabled()) {
			log.debug("login save..........");
			log.debug(columnProperty.getId());
		}
		try{
		if (columnProperty.getId() == null || "".equals(columnProperty.getId().trim())) {// new 
			columnProperty.setCreateDate(new Date());
			columnProperty.setCreateUserId(getUserId());
			columnProperty.setRecycled("0");
			columnProperty=columnPropertyService.saveColumnPropertyBean(columnProperty);
			setMyMessage(getText("entity.saved"));
		} else {// update
			columnPropertyService.updateColumnPropertyBean(columnProperty);
			setMyMessage(getText("entity.updated"));
		}}catch(Exception e){
			e.printStackTrace();
		}
		startTime = System.currentTimeMillis() - startTime;
		if (log.isDebugEnabled()) {
			log.debug("time ms:::::" + startTime);
			System.out.println("time ms:::::" + startTime);
		}
		return super.save();
	}
	public String dwrSave(ColumnPropertyBean bean) throws Exception {
		long startTime = System.currentTimeMillis();
		if (log.isDebugEnabled()) {
			log.debug("login save..........");
			log.debug(bean.getId());
		}
		try{
		if (bean.getId() == null || "".equals(bean.getId())) {// new 
			columnPropertyService.saveColumnPropertyBean(bean);
		} else {// update
			columnPropertyService.updateColumnPropertyBean(bean);
		}}catch(Exception e){
			e.printStackTrace();
		}
		startTime = System.currentTimeMillis() - startTime;
		if (log.isDebugEnabled()) {
			log.debug("time ms:::::" + startTime);
			System.out.println("time ms:::::" + startTime);
		}
		return super.dwrBaseSave(bean.getId());
	}
	public String delete() throws Exception {
		long startTime = System.currentTimeMillis();
		if (log.isDebugEnabled()) {
			log.debug("login delete..........");
			log.debug(getId());
		}
		if(getId().indexOf(",")>=0){
			columnPropertyService.removeColumnPropertyBeanByIds(getId());
		}else{
			columnPropertyService.removeColumnPropertyBeanById(getId());
		}
		startTime = System.currentTimeMillis() - startTime;
		if (log.isDebugEnabled()) {
			log.debug("time ms:::::" + startTime);
			System.out.println("time ms:::::" + startTime);
		}
		columnProperty=null;
		return super.delete();
	}
	public String dwrDelete(String id) throws Exception {
		long startTime = System.currentTimeMillis();
		if (log.isDebugEnabled()) {
			log.debug("login delete..........");
			log.debug(id);
		}
		if(id.indexOf(",")>=0){
			columnPropertyService.removeColumnPropertyBeanByIds(id);
		}else{
			columnPropertyService.removeColumnPropertyBeanById(id);
		}
		startTime = System.currentTimeMillis() - startTime;
		if (log.isDebugEnabled()) {
			log.debug("time ms:::::" + startTime);
			System.out.println("time ms:::::" + startTime);
		}
		return super.dwrBaseDelete(id);
	}
	
}